package Week2;

import java.util.*;

public class Day11 {
}


//牛客:游游的水果大礼包
class Main9 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextInt();
        long m = in.nextInt();
        long a = in.nextInt();
        long b = in.nextInt();
        long ret = 0;
        //枚举所有的情况，取最大值
        for(long x = 0; x <= Math.min(n / 2 , m); x++){
            long y = Math.min(n - x * 2 , (m - x) / 2);
            ret = Math.max(ret, a * x + b * y);
        }
        System.out.println(ret);
    }
}

//牛客:DP31 买卖股票的最好时机(二)
class Main {
    //贪心
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] prices = new int[n];
        for(int i = 0; i < n; i++){
            prices[i] = in.nextInt();
        }
        int ret = 0;
        for(int i = 1; i < n; i++){
            //如果后一个比前一个大就购买和卖出得到获得的利润
            if(prices[i] > prices[i-1]){
                ret += prices[i] - prices[i-1];
            }
        }
        System.out.println(ret);
    }
}

//牛客:OR62 倒置字符串
//方法一:
class Main10 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] ch = in.nextLine().toCharArray();
        int n = ch.length;
        //翻转整个字符数组
        reverse(ch, 0, n - 1);

        int left = 0 , right = 0;
        //不是空格就往下走
        while(right < n){
            while(right < n && ch[right] != ' '){
                right++;
            }
            //遇到空格就进行区间翻转
            reverse(ch,left,right-1);
            //跳过空格
            while(right < n && ch[right] == ' '){
                right++;
            }
            //更新左边界left
            left = right;
        }
        //打印数组
        for(char c : ch){
            System.out.print(c);
        }
    }
    //字符区间翻转
    public static void reverse (char[] ch, int i, int j) {
        while (i < j) {
            char tmp = ch[i];
            ch[i] = ch[j];
            ch[j] = tmp;
            i++;
            j--;
        }
    }
}

//方法二:
class Main11 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int n = s.length();
        String[] str = new String[n];
        int left = 0;
        int right = 0;
        int i = 0;
        //将字符串转换为字符串数组，遇到空格分开
        while(right < n){
            if(right < n && s.charAt(right) == ' '){
                //从字符串中取出
                str[i++] = s.substring(left,right);
                left = right + 1;
            }
            right++;
        }
        str[i] = s.substring(left,right);
        //将字符串数组放入栈中
        Stack<String> stack = new Stack<>();
        for(int j = 0; j <= i; j++){
            stack.push(str[j]);
        }

        //弹出
        while(!stack.isEmpty()){
            System.out.print(stack.pop()+" ");
        }
    }
}